Setup

library(sf)
library(tidyverse)
library(rgeoboundaries)
library(osmextract)
library(tmap)
library(kableExtra)
library(lubridate)
library(DT)


hex_grid <- st_read("/Users/charlie/Downloads/hex_grid_join172.gpkg")
## Reading layer `hex_grid_join172' from data source 
##   `/Users/charlie/Downloads/hex_grid_join172.gpkg' using driver `GPKG'
## Simple feature collection with 688 features and 14 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: 36.65346 ymin: -1.457928 xmax: 37.11389 ymax: -1.138157
## Geodetic CRS:  WGS 84
nairobi_roads <- st_read("/Users/charlie/WRI_Nairobi/data/semhol_diff.gpkg")
## Reading layer `semhol_diff' from data source 
##   `/Users/charlie/WRI_Nairobi/data/semhol_diff.gpkg' using driver `GPKG'
## Simple feature collection with 15929 features and 8 fields
## Geometry type: LINESTRING
## Dimension:     XY
## Bounding box:  xmin: 36.65535 ymin: -1.510086 xmax: 37.08296 ymax: -1.036557
## Geodetic CRS:  WGS 84

1 Uber OSM Analysis

Match between OSM and Uber road segments.

Match between OSM and Uber road segments.

Total OSM road length for Nairobi.

Total OSM road length for Nairobi.

OSM highway type coverage

OSM highway type coverage

2 Road speeds

2.1 Daily Mean Road speeds

Daily mean road speeds during the morning rush hour 6-9am with semester and holiday means and standard errors. Semester and holiday means and standard errors were calculated on all road speeds for all segments between the 6-9 am window for each respective period.

Daily mean road speeds during the morning rush hour 6-9am with semester and holiday means and standard errors. Semester and holiday means and standard errors were calculated on all road speeds for all segments between the 6-9 am window for each respective period.

2.2 Anomalies

extreme20_days <- read_csv("data/extreme20_daysNairobi.csv")
print(extreme20_days)
## # A tibble: 20 × 2
##    date       mean_speed_kph
##    <date>              <dbl>
##  1 2019-12-27           42.4
##  2 2019-12-31           42.0
##  3 2019-01-02           41.6
##  4 2019-12-30           41.0
##  5 2019-12-24           38.6
##  6 2019-01-03           38.4
##  7 2019-12-23           37.9
##  8 2019-01-04           37.7
##  9 2019-08-26           35.8
## 10 2019-08-16           35.5
## 11 2019-12-03           30.5
## 12 2019-10-23           30.7
## 13 2019-01-29           30.8
## 14 2019-01-30           30.8
## 15 2019-12-10           31.0
## 16 2019-02-05           31.0
## 17 2019-06-06           31.1
## 18 2019-10-24           31.2
## 19 2019-11-26           31.2
## 20 2019-01-23           31.2

##Mean Road speeds by Road Type

Daily mean road speeds split by OSM highway type.

Daily mean road speeds split by OSM highway type.

3 Maps

3.1 Map of mean road speed difference between holiday and school semester period

Facet map of mean speed differences for each road segment between the semester and holiday periods. Facets are for all road types, primary and trunk, secondary, and tertiary and residential.

Facet map of mean speed differences for each road segment between the semester and holiday periods. Facets are for all road types, primary and trunk, secondary, and tertiary and residential.

3.2 Map of travel time loss between school semester and holiday throughout the network

Hexgrid of travel time loss between the semester and holiday period as measured by aggregate seconds lost when routing from the origin hexagon to all other hexagons

Hexgrid of travel time loss between the semester and holiday period as measured by aggregate seconds lost when routing from the origin hexagon to all other hexagons

 
tmap_mode("view")

m.1 <- tm_basemap("OpenStreetMap.HOT") +
  tm_shape(nairobi_roads) +
  tm_lines(
    col = "mean_speed_diff",
    palette = "Spectral",
    n=5,
    lwd = 2,
    breaks = c(-100,-5,-2,2,5,100),
    popup.vars = c("osmhighway", "mean_speed_diff")
  )


m.1